﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AIproject
{
    class Literal
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="modelin">model</param>
        public Literal(Model modelin)
        {
            model = modelin;
        }

        private Model model;
        private bool negation;
        private string literalName;

        public string SymbolName
        {
            get
            {
                return literalName;
            }
            set
            {
                literalName = value;
            }
        }

        public bool isNegation
        {
            get
            {
                return negation;
            }
            set
            {
                negation = value;
            }
        }

        /// <summary>
        /// This funtion returns the evaluation of the literal using the existing model
        /// </summary>
        /// <returns>boolean value</returns>
        public bool evaluate()
        {
            bool tempbool;
            if (negation)
            {
                //return the negated value
                model.TryGetValue(this.literalName, out tempbool);
                return !(tempbool);
            }
            else
            {
                model.TryGetValue(this.literalName, out tempbool);
                return (tempbool);
            }
        }

        /// <summary>
        /// literal is same as this one
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public bool isSame(Literal a)
        {
            if (this.isNegation == a.isNegation && this.SymbolName == a.SymbolName)
                return true;
            return false;
        }


        

    }
}
